
function getUrlPlain() {
if (!localStorage.match_url)
localStorage.match_url = "";
return localStorage.match_url;
}

function getUrlMatches() {
return expandMatches(getUrlPlain());
}

function expandMatches(urls) {
var list = urls.split('\n');
var list_regex = [];
for (var i = 0; i < list.length; ++i)
 {  if (list[i] != "")
 {  list_regex.push(new RegExp(list[i]));  }}
return list_regex;
}

function isUrlMatched(url) {
var list = getUrlMatches();
for (var i = 0; i < list.length; ++i) {
if (list[i].test(url)) return true;
}
return false;
}

function setUrlMatches(urls) {
localStorage.match_url = urls;
}

function getResponse(request, tab) {
if (request.command == "ActionList") {
var response = new Object();
response.replace = isUrlMatched(request.url);
response.checkForm = (request.id != "");
return response;
}
}

function startListener() {
chrome.extension.onRequest.addListener(
 function(request, sender, sendResponse) {
  if (!sender.tab) {
     console.error("Illegal call");
  }
  var response = getResponse(request, sender.tab);
  console.log(response);
  sendResponse(response);
});
}
